Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show errors in the media replace control #19244

Merged
merged 6 commits into from
Mar 13, 2020
Merged

Conversation

draganescu
Copy link
Contributor

Description

Closes #19156
If there is an upload error in the media replace control this PR displays the error

How has this been tested?

Tested locally, desktop and mobile.

Screenshots

media-flow-show-errors

Types of changes

Non breaking, added the noticesUI.

@draganescu draganescu added Needs Design Feedback Needs general design feedback. [Block] Image Affects the Image Block labels Dec 19, 2019
@mtias
Copy link
Member

mtias commented Dec 19, 2019

It is a bit weird to render an error notice inside a dropdown. Can we render the error using the snackbar notices instead?

@draganescu
Copy link
Contributor Author

draganescu commented Dec 19, 2019

@mtias I thought about that as well, but in #19156 @karmatosed advised against that route:

I would advise against snackbars for this as it's not right by where the error occurs and it's also the wrong use of that style of the component.

In this light I agree with the same, the error would be to offsite from where the action happened. Nevertheless this option implemented here also feels "too contextual", which means cramped.

Tammie also provided another option where the error would be stuck to the component that implements / uses MediaReplaceFlow but that would require updates to all these components, I believe.

@karmatosed
Copy link
Member

karmatosed commented Dec 19, 2019

Correct, the drop-down wasn't only space I suggested, there was within placeholder which could also work. For me, I felt the snack bar was unexpected as not used in other cases for that.

image

@mtias
Copy link
Member

mtias commented Dec 19, 2019

Inline notices for async operations are tricky because the user might have scrolled or moved their attention elsewhere. The snackbar fits the paradigm better in my mind as it can also increase consistency if more blocks use it.

@enriquesanchez
Copy link
Contributor

Agreed that the snackbar would not be ideal for the reasons stated. I would look at Tammie's proposal, having the error appear in the placeholder sounds right to me.

@mtias
Copy link
Member

mtias commented Dec 20, 2019

There's no placeholder there.

@jasmussen
Copy link
Contributor

Rendering the error inside the dropdown is not a very scalable way. Rendering it on the block itself, while "geographically in context", is also not necessarily ideal as it would not work for a really really small image.

To me, the two existing notice mechanisms are appropriate to use, either the snackbar which reads the error aloud to screen readers, or the Notice, which shows at the top. Which to use depends on how serious we think the error is.

By using either of those not only do we use the same notices we use for virtually everything else, we ensure that they are visible both when the image is REALLY small, or even if you upload, then scroll the block out of view (both are fixed position).

@draganescu
Copy link
Contributor Author

@jasmussen which notices show "at the top"?

@jasmussen
Copy link
Contributor

The <Notice /> (I believe) https://developer.wordpress.org/block-editor/components/notice/

@karmatosed
Copy link
Member

karmatosed commented Dec 20, 2019

At the moment we are using different places for messages and we unless mistaken (which might be) don't use snack bars for error messages. I think aside from this issue looking at an audit and then clearly noting in docs what area we use for what, under what situation, notices is key going forward and will help everyone. This makes it easier for people to just pop in whatever context notice applies in future.

I made this to start that process (low priority but good to do in the new year): #19277

@mapk
Copy link
Contributor

mapk commented Dec 27, 2019

I'll add that snackbars are great for quickly reading through an update message or something similar. An error message always takes me more time to read and understand what's going wrong. Snackbars as error messages can cause an increase in anxiety trying to read the error before it goes away... If we're going with existing notifications, I think using an error notification in the top works well.

@draganescu
Copy link
Contributor Author

Screenshot 2020-01-06 at 16 00 29

Using default notices seems better than contextual for this kind of message, as it is generated by the, what looks like, general UI of the editor.

Media errors are most likely to happen because of system level settings or issues, therefore they're not contextual to the component that uses and displays media.

Snackbars, as @mapk also explained above, are not yet suitable for errors which need to sometimes be debugged or forwarded to other people. Contextual errors are not suited for UI elements.

@Soean Soean added the Needs Accessibility Feedback Need input from accessibility label Jan 13, 2020
@Soean
Copy link
Member

Soean commented Jan 13, 2020

Works! I added the a11y feedback label, to get a another review..

Some ideas:

  • Add an ID to the notice, so the old notice will be replaced, if we get the notice again.
  • Remove the notice, if the URL was updated successful.

@draganescu
Copy link
Contributor Author

Thanks @Soean great suggestions added them both in 5865361 !

@afercia
Copy link
Contributor

afercia commented Feb 19, 2020

Testing with Safari and VoiceOver, the speak message is not announced.

I guess this is because timing:

  1. the notice appears and the speak message runs
  2. focus is moved back to the "Upload" menu item

An aria-live assertive message can only interrupts anything the screen reader is announcing in that moment. Focus is set back to the menu item immediately after the speak message happens so the screen reader just announces the newly focused element.

I think the notice should be slightly delayed or "put in the queue" after the focus thing.

I tested adding a quick'n dirty setTimeout and that made the speak message work. I guess there's a cleaner way in Gutenberg to delay / defer a function call.

@afercia afercia added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). and removed Needs Accessibility Feedback Need input from accessibility labels Feb 19, 2020
@enriquesanchez
Copy link
Contributor

Hey @draganescu!

I tried testing this PR but I'm getting an unexpected error. I just wanted to confirm if I should be doing anything on my side in addition to just switching to this branch?

When uploading a ~18MB JPEG, I get this error:

Screen Shot 2020-02-19 at 11 41 20

@github-actions
Copy link

github-actions bot commented Feb 20, 2020

Size Change: +293 B (0%)

Total Size: 856 kB

Filename Size Change
build/block-editor/index.js 100 kB +158 B (0%)
build/block-editor/style-rtl.css 10.7 kB +70 B (0%)
build/block-editor/style.css 10.7 kB +65 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.01 kB 0 B
build/annotations/index.js 3.43 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-library/editor-rtl.css 7.23 kB 0 B
build/block-library/editor.css 7.24 kB 0 B
build/block-library/index.js 111 kB 0 B
build/block-library/style-rtl.css 7.38 kB 0 B
build/block-library/style.css 7.39 kB 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 57.7 kB 0 B
build/components/index.js 191 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 5.76 kB 0 B
build/core-data/index.js 10.6 kB 0 B
build/data-controls/index.js 1.04 kB 0 B
build/data/index.js 8.21 kB 0 B
build/date/index.js 5.37 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.06 kB 0 B
build/edit-post/index.js 91.3 kB 0 B
build/edit-post/style-rtl.css 8.64 kB 0 B
build/edit-post/style.css 8.64 kB 0 B
build/edit-site/index.js 4.64 kB 0 B
build/edit-site/style-rtl.css 2.48 kB 0 B
build/edit-site/style.css 2.48 kB 0 B
build/edit-widgets/index.js 4.45 kB 0 B
build/edit-widgets/style-rtl.css 2.58 kB 0 B
build/edit-widgets/style.css 2.58 kB 0 B
build/editor/editor-styles-rtl.css 381 B 0 B
build/editor/editor-styles.css 382 B 0 B
build/editor/index.js 43.8 kB 0 B
build/editor/style-rtl.css 3.97 kB 0 B
build/editor/style.css 3.96 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.09 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 1.92 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.49 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.3 kB 0 B
build/keycodes/index.js 1.68 kB 0 B
build/list-reusable-blocks/index.js 2.99 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 4.85 kB 0 B
build/notices/index.js 1.57 kB 0 B
build/nux/index.js 3.01 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.49 kB 0 B
build/priority-queue/index.js 779 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/rich-text/index.js 14.3 kB 0 B
build/server-side-render/index.js 2.55 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.01 kB 0 B
build/viewport/index.js 1.61 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@draganescu
Copy link
Contributor Author

So I added a debounced call to speak, it does work, but it seems like a hack rather than a solution. I'll see if I can get any help on a better solution.

@youknowriad
Copy link
Contributor

+23 kB

That's a big change for such a small diff. I wonder if there's a bug with the bundle size bot somehow. As far as I know the deps here are externals so, they shouldn't impact the bundle size that much. Any ideas @gziolo @nerrad @jsnajdr

@draganescu sorry for squatting your PR for an unrelated thing :)

@youknowriad
Copy link
Contributor

@draganescu how fresh is this branch compared to master, asking cause I'm wondering if it's because it's not rebased recently enough which could cause the big diff.

@youknowriad
Copy link
Contributor

Ok, now the numbers make more sense (after a rebase). I'll open an issue on the Github action tracker to see if we can have better numbers without requiring rebases.

@enriquesanchez
Copy link
Contributor

I just tested it and got the same results as @afercia.

So I added a debounced call to speak, it does work, but it seems like a hack rather than a solution.

If it's possible, I think the idea of putting it in the queue might work better.

@draganescu
Copy link
Contributor Author

@enriquesanchez but I did add that, the current version of the PR speaks the message with a delay. It seems five seconds were enough to wait for VO to speak all the stuff before the error, but if it still didnt work for you, then it means this is not the way to do it :)

@aduth
Copy link
Member

aduth commented Feb 25, 2020

Notice has a built-in speak mechanism (recently updated as of #15745), which I think has relevance here in one of two ways:

  • Ideally we rely on the built-in speak behavior of notice, rather than calling speak directly. Per the previous conversation, would it be enough to change the order of the programmatic focus vs. createNotice to ensure that focus is shifted before the notice is created?
    • If both need to be announced, and can't interoperate (queue) themselves, then could we instead defer the notice creation after the delay, rather than speak? It's a bit uncomfortable to me that in addition to the code duplication of recreating the speak behavior, we also have different timing for the notice and the message.
  • At the very least, we should disable the Notice's default speak handling, via speak: false option (reference), if it's going to be handled via a separate implementation.

@enriquesanchez
Copy link
Contributor

hey @draganescu 👋

but I did add that, the current version of the PR speaks the message with a delay

Oh, I'm sorry. I must have not properly build after switching branches. I tested it again, and I heard the error being announced this time 🎉

Because focus moves back to the first menu item in the replace popover, VoiceOver announces this first. Then the error is announced. This confused me a bit.

Ideally the error could be announced before focus moves, but I'm not sure if this is technically possible?

@afercia would a scenario like the described above be correct? Should the error be announced before any focus change?

@draganescu
Copy link
Contributor Author

Following @aduth 's suggestion above instead of delaying the speak, I delayed the notice creation and use the built in speak mechanism instead. In my testing it worked very well. @enriquesanchez if you can please conform this is the case for you as well that'd be great!

@enriquesanchez
Copy link
Contributor

hey @draganescu!

I just tested it and it worked as expected, so much better! 👍👍

@draganescu draganescu merged commit c0c924a into master Mar 13, 2020
@draganescu draganescu deleted the add/media-flow-errors branch March 13, 2020 09:00
@github-actions github-actions bot added this to the Gutenberg 7.8 milestone Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Media replace flow doesn't show errors